package cn.iocoder.yudao.module.cfs.controller.admin.datanbusermonitorinfo;

import cn.iocoder.yudao.module.cfs.controller.admin.datanbusermonitorinfo.vo.DataNbUsermonitorinfoPageReqVO;
import cn.iocoder.yudao.module.cfs.controller.admin.datanbusermonitorinfo.vo.DataNbUsermonitorinfoRespVO;
import cn.iocoder.yudao.module.cfs.controller.admin.datanbusermonitorinfo.vo.DataNbUsermonitorinfoSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.cfs.dal.dataobject.datanbusermonitorinfo.DataNbUsermonitorinfoDO;
import cn.iocoder.yudao.module.cfs.service.datanbusermonitorinfo.DataNbUsermonitorinfoService;

@Tag(name = "管理后台 - 联网设备NB类型")
@RestController
@RequestMapping("/cfs/data-nb-usermonitorinfo")
@Validated
public class DataNbUsermonitorinfoController {

    @Resource
    private DataNbUsermonitorinfoService dataNbUsermonitorinfoService;

    @PostMapping("/create")
    @Operation(summary = "创建联网设备NB类型")
    @PreAuthorize("@ss.hasPermission('cfs:data-nb-usermonitorinfo:create')")
    public CommonResult<Long> createDataNbUsermonitorinfo(@Valid @RequestBody DataNbUsermonitorinfoSaveReqVO createReqVO) {
        return success(dataNbUsermonitorinfoService.createDataNbUsermonitorinfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新联网设备NB类型")
    @PreAuthorize("@ss.hasPermission('cfs:data-nb-usermonitorinfo:update')")
    public CommonResult<Boolean> updateDataNbUsermonitorinfo(@Valid @RequestBody DataNbUsermonitorinfoSaveReqVO updateReqVO) {
        dataNbUsermonitorinfoService.updateDataNbUsermonitorinfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除联网设备NB类型")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('cfs:data-nb-usermonitorinfo:delete')")
    public CommonResult<Boolean> deleteDataNbUsermonitorinfo(@RequestParam("id") Long id) {
        dataNbUsermonitorinfoService.deleteDataNbUsermonitorinfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得联网设备NB类型")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('cfs:data-nb-usermonitorinfo:query')")
    public CommonResult<DataNbUsermonitorinfoRespVO> getDataNbUsermonitorinfo(@RequestParam("id") Long id) {
        DataNbUsermonitorinfoDO dataNbUsermonitorinfo = dataNbUsermonitorinfoService.getDataNbUsermonitorinfo(id);
        return success(BeanUtils.toBean(dataNbUsermonitorinfo, DataNbUsermonitorinfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得联网设备NB类型分页")
    @PreAuthorize("@ss.hasPermission('cfs:data-nb-usermonitorinfo:query')")
    public CommonResult<PageResult<DataNbUsermonitorinfoRespVO>> getDataNbUsermonitorinfoPage(@Valid DataNbUsermonitorinfoPageReqVO pageReqVO) {
        PageResult<DataNbUsermonitorinfoDO> pageResult = dataNbUsermonitorinfoService.getDataNbUsermonitorinfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DataNbUsermonitorinfoRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出联网设备NB类型 Excel")
    @PreAuthorize("@ss.hasPermission('cfs:data-nb-usermonitorinfo:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDataNbUsermonitorinfoExcel(@Valid DataNbUsermonitorinfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DataNbUsermonitorinfoDO> list = dataNbUsermonitorinfoService.getDataNbUsermonitorinfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "联网设备NB类型.xls", "数据", DataNbUsermonitorinfoRespVO.class,
                        BeanUtils.toBean(list, DataNbUsermonitorinfoRespVO.class));
    }

}